<?php
namespace Pay\Service\Alipay;

use Pay\Config\Alipay;

class ActionAbstract
{
    protected $config;
    protected $aopclient;

    public function __construct($config = false) {
        $this->config = (new Alipay())->config();
        if ($config) {
            $this->config = $config;
        }

        //验证一些参数
        $this->paramsFormat();

        $this->baseAop();
    }

    /*
     *执行支付宝支付的基类效果
     */
    protected function baseAop()
    {
        $ret = include (__DIR__ . '/../../Alipay/AopClient.php');

        $this->aopclient = new \AopClient;
        $this->aopclient->gatewayUrl = $this->config['gatewayUrl'];
        $this->aopclient->appId = $this->config['appId'];
        $this->aopclient->alipayrsaPublicKey = $this->config['publicKey'];
        $this->aopclient->rsaPrivateKey = $this->config['privateKey'];
        $this->aopclient->format = $this->config['format'];
        $this->aopclient->charset = $this->config['charset'];
        $this->aopclient->signType = $this->config['signType'];
    }

    protected function paramsFormat()
    {
        if (!$this->config['appId']) {
            throw new \Exception('appId不能为空!');
        }
        if (!$this->config['publicKey'] || !$this->config['privateKey']) {
            throw new \Exception('秘钥不能为空!');
        }
    }
}
?>
